package de.dhbw.tinf11b.vfb;

import java.util.Map;
import java.util.Map.Entry;

import de.dhbw.tinf11b.vfb.exceptions.WeightingsMismatchException;

public class Module {
	
	protected String name;
	protected Map<Unit, Float> units; // the units of this module and associated weighting
	protected int semester;
	protected int credits;
	protected int semesterWeekHours; // Semesterwochenstunden: Anzahl der Vorlesungsstuden pro Woche
	protected int practiceHours;	// Praxisstunden: Anzahl der Stunden, die im Betrieb abgesessen werden müssen
	protected int presence; // Präsenz: Zahl der Studen, die in der Uni abgesessen werden müssen
	protected int selfStudyHours; // Eigenstudium: Zahl der Stunden, die man sich zu Hause mit dem Thema beschäfteln sollte (höhö)
	
	
	public Module(String name, Map<Unit, Float> units, int semester, int credits, int presence, int selfStudyHours) throws WeightingsMismatchException {
		
		this.checkWeightings(units);
		this.name = name;
		this.units = units;
		this.semester = semester;
		this.credits = credits;
		this.presence = presence;
		this.selfStudyHours = selfStudyHours;
	}
	
	private void checkWeightings(Map<Unit, Float> units) throws WeightingsMismatchException {
		float sumWeightings = 0;
		for (Entry<Unit, Float> unitEntry : units.entrySet()) {
			Float weighting = unitEntry.getValue();
			sumWeightings = sumWeightings + weighting;
		}
		if (sumWeightings != 1.0) {
			throw new WeightingsMismatchException();
		}
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Map<Unit, Float> getUnits() {
		return units;
	}


	public void setUnits(Map<Unit, Float> units) {
		this.units = units;
	}


	public int getSemester() {
		return semester;
	}


	public void setSemester(int semester) {
		this.semester = semester;
	}


	public int getCredits() {
		return credits;
	}


	public void setCredits(int credits) {
		this.credits = credits;
	}


	public int getSemesterWeekHours() {
		return semesterWeekHours;
	}


	public void setSemesterWeekHours(int semesterWeekHours) {
		this.semesterWeekHours = semesterWeekHours;
	}


	public int getPracticeHours() {
		return practiceHours;
	}


	public void setPracticeHours(int practiceHours) {
		this.practiceHours = practiceHours;
	}


	public int getWorkload() {
		return presence + selfStudyHours;
	}



	public int getPresence() {
		return presence;
	}


	public void setPresence(int presence) {
		this.presence = presence;
	}


	public int getSelfStudyHours() {
		return selfStudyHours;
	}


	public void setSelfStudyHours(int selfStudyHours) {
		this.selfStudyHours = selfStudyHours;
	}
	
	
}
